﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace jQueryDotNetLib.Extenders
{
    public enum ToleranceOptions {fit, intersect, pointer, touch};

    [ToolboxItem(true)]
    [ToolboxData("<{0}:Droppable Selector=\"\" runat=server />")]
    public class Droppable : BaseInteractionExtender
    {
        public Droppable()
        {
            Interaction = "droppable";
        }

        [Bindable(true)]
        [Category("Client Events")]
        [DefaultValue("")]
        [Localizable(true)]
        public string OnClientDropActivate
        {
            get
            {
                if (ViewState["OnClientDropActivate"] == null) return "";
                return (string)ViewState["OnClientDropActivate"];
            }

            set
            {
                ViewState["OnClientDropActivate"] = value;
            }
        }
        [Bindable(true)]
        [Category("Client Events")]
        [DefaultValue("")]
        [Localizable(true)]
        public string OnClientDropDeactivate
        {
            get
            {
                if (ViewState["OnClientDropDeactivate"] == null) return "";
                return (string)ViewState["OnClientDropDeactivate"];
            }

            set
            {
                ViewState["OnClientDropDeactivate"] = value;
            }
        }
        [Bindable(true)]
        [Category("Client Events")]
        [DefaultValue("")]
        [Localizable(true)]
        public string OnClientDropDrop
        {
            get
            {
                if (ViewState["OnClientDropDrop"] == null) return "";
                return (string)ViewState["OnClientDropDrop"];
            }

            set
            {
                ViewState["OnClientDropDrop"] = value;
            }
        }
        [Bindable(true)]
        [Category("Client Events")]
        [DefaultValue("")]
        [Localizable(true)]
        public string OnClientDropOver
        {
            get
            {
                if (ViewState["OnClientDropOver"] == null) return "";
                return (string)ViewState["OnClientDropOver"];
            }

            set
            {
                ViewState["OnClientOver"] = value;
            }
        }
        [Bindable(true)]
        [Category("Client Events")]
        [DefaultValue("")]
        [Localizable(true)]
        public string OnClientDropOut
        {
            get
            {
                if (ViewState["OnClientDropOut"] == null) return "";
                return (string)ViewState["OnClientDropOut"];
            }

            set
            {
                ViewState["OnClientDropOut"] = value;
            }
        }









        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Accept
        {
            get
            {
                if (ViewState["Accept"] == null) return "";
                return (string)ViewState["Accept"];
            }

            set
            {
                ViewState["Accept"] = value;
            }
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string ActiveClass
        {
            get
            {
                if (ViewState["ActiveClass"] == null) return "";
                return (string)ViewState["ActiveClass"];
            }

            set
            {
                ViewState["ActiveClass"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public bool AddClasses
        {
            get
            {
                if (ViewState["AddClasses"] == null) return true;
                return (bool)ViewState["AddClasses"];
            }

            set
            {
                ViewState["AddClasses"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public bool Greedy
        {
            get
            {
                if (ViewState["Greedy"] == null) return false;
                return (bool)ViewState["Greedy"];
            }

            set
            {
                ViewState["Greedy"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string HoverClass
        {
            get
            {
                if (ViewState["HoverClass"] == null) return "";
                return (string)ViewState["HoverClass"];
            }

            set
            {
                ViewState["HoverClass"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Scope
        {
            get
            {
                if (ViewState["Scope"] == null) return "default";
                return (string)ViewState["Scope"];
            }

            set
            {
                ViewState["Scope"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public ToleranceOptions Tolerance
        {
            get
            {
                if (ViewState["Tolerance"] == null) return ToleranceOptions.intersect;
                return (ToleranceOptions)ViewState["Tolerance"];
            }

            set
            {
                ViewState["Tolerance"] = value;
            }
        }


        protected override void Render(HtmlTextWriter writer)
        {

            if (Accept != "") AddParameter("accept", "'" + Accept + "'");
            if (ActiveClass != "") AddParameter("activeClass", "'" + ActiveClass + "'");
            if (!AddClasses) AddParameter("addClasses", "'" + AddClasses + "'");
            if (Greedy) AddParameter("greedy","true");
            if (HoverClass != "") AddParameter("hoverClass", "'" + HoverClass + "'");
            if (Scope != "default") AddParameter("scope", "'" + Scope + "'");
            if (Tolerance != ToleranceOptions.intersect) AddParameter("tolerance", "'" + Tolerance.ToString() + "'");

            AddBinding("activate", OnClientDropActivate);
            AddBinding("deactivate", OnClientDropDeactivate);
            AddBinding("over", OnClientDropOver);
            AddBinding("out", OnClientDropOut);
            AddBinding("drop", OnClientDropDrop);
            base.Render(writer);
        }

    }
}
